from mako.template import Template
import builtins
from pathlib import Path
import sys
import os


def GetBuiltinNamesAndDocs():
    return [(name, getattr(builtins, name).__doc__)
            for name in dir(builtins) if not name.startswith('_')]


if __name__ == "__main__":
    names = GetBuiltinNamesAndDocs()
    tmpl = Template(Path(__file__).with_name(
        'builtin_names.h.mako').read_text())
    text = tmpl.render(names=names)
    output = sys.argv[1]
    Path(output).write_text(text)
    os.system('clang-format -style=Google -i {}'.format(output))

